from sqlalchemy import Column, String, Integer
from werkzeug.security import generate_password_hash, check_password_hash

from .base import Base


class Admin(Base):
    id = Column(Integer, primary_key=True)
    username = Column(String(50), nullable=False, unique=True)
    _password = Column(String(255), nullable=False)

    @property
    def password(self):
        return self._password

    @password.setter
    def password(self, raw_pwd):
        self._password = generate_password_hash(raw_pwd)

    def check_password(self, raw_pwd):
        return check_password_hash(self.password, raw_pwd)


